using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

namespace ClientTools.Server.Controls
{
    public class TreeHandler : umbraco.interfaces.ITree
    {
        private int _id;
        private string _app;

        #region ITree Member

        public void Render(ref System.Xml.XmlDocument tree)
        {
            XmlNode root = tree.DocumentElement;

            XmlElement treeElement = tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "1");
            treeElement.SetAttribute("text", "Log Viewer");
            treeElement.SetAttribute("action", "javascript:openLogViewer();");
            treeElement.SetAttribute("menu", "D");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingXML.gif");
            treeElement.SetAttribute("openIcon", "settingXML.gif");
            treeElement.SetAttribute("nodeType", "LogViewer");
            
            root.AppendChild(treeElement);

            treeElement = tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "2");
            treeElement.SetAttribute("text", "Versions");
            treeElement.SetAttribute("action", "javascript:openVersions();");
            treeElement.SetAttribute("menu", "D");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingXML.gif");
            treeElement.SetAttribute("openIcon", "settingXML.gif");
            treeElement.SetAttribute("nodeType", "Versions");

            root.AppendChild(treeElement);

            treeElement = tree.CreateElement("tree");
            treeElement.SetAttribute("nodeID", "3");
            treeElement.SetAttribute("text", "Statistics");
            treeElement.SetAttribute("action", "javascript:openStats();");
            treeElement.SetAttribute("menu", "D");
            treeElement.SetAttribute("src", "");
            treeElement.SetAttribute("icon", "settingXML.gif");
            treeElement.SetAttribute("openIcon", "settingXML.gif");
            treeElement.SetAttribute("nodeType", "Stats");

            root.AppendChild(treeElement);
        }

        public void RenderJS(ref System.Text.StringBuilder javascript)
        {
            javascript.Append(@"
                function openLogViewer() 
                {
	                parent.right.document.location.href = 'plugins/clienttools/LogViewer.aspx';
                }");
            javascript.Append(@"
                function openVersions() 
                {
	                parent.right.document.location.href = 'plugins/clienttools/Versions.aspx';
                }");
            javascript.Append(@"
                function openStats() 
                {
	                parent.right.document.location.href = 'plugins/clienttools/Stats.aspx';
                }");
        }

        public string app
        {
            set { this._app = value; }
        }

        public int id
        {
            set { this._id = value; }
        }

        #endregion
    }
}
